<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/11/9
 * Time: 11:25
 */

namespace app\modules\factoryMethod\factory;


use app\modules\factoryMethod\vehicle\AbstractVehicle;
use app\modules\factoryMethod\vehicle\Bicycle;
use app\modules\factoryMethod\vehicle\CardMercedes;
use yii\base\Exception;

/**
 * Class GermanFactory
 * @package app\modules\factoryMethod\factory
 */
class GermanFactory extends AbstractFactoryMethod
{
    /**
     * className
     *
     * @date   2018/11/9
     * @author edmmss
     * @param string $type
     * @return AbstractVehicle
     */
    public function createVehicle(string $type): AbstractVehicle
    {
        // TODO: Implement createVehicle() method.
        switch ($type) {
            case parent::TYPE_CHEAP:
                $vehicle = new Bicycle();
                $vehicle->addBasket('德国');

                return $vehicle;
                break;
            case parent::TYPE_FAST:
                $vehicle = new CardMercedes();
                $vehicle->addMercedesSpeaker();

                return $vehicle;
                break;
            default:
                throw new Exception("{$type} is not a valid vehicle");
        }
    }
}